﻿$(function() {
    JSUtility.param.ClassName = "OA.Bll.Project.ProjectProgressInfoPresenter";
    JSUtility.param.Options["InternalType"] = "0";

    autoResize({ dataGrid: '#Grid', callback: Initlist });

    JSUtility.window_edit = $('#Add').window({
        iconCls: 'icon-add',
        zIndex: 1000,
        draggable: true,
        resizable: false,
        shadow: true,
        inline: true,
        modal: true,
        title: '添加项目执行信息',
        collapsible: false,
        minimizable: false,
        maximizable: false,
        closable: true,
        width: 480,
        //height: 420,
        closed: true,
        onOpen: function() {
            $('#Add').parent().css("left", "25%");
            $('#Add').parent().next().css("left", "25%");
            $('#Add').parent().next().css("top", "25%");
            $('#Add').parent().css("top", "25%");
        }
    });
    JSUtility.window_edit_title = "项目执行信息";
    JSUtility.window_edit_form = $('#Add').find("form");
    $('#Add').show();
    ComboboxInitial();
});

function ComboboxInitial() {
    if (!self.parent.projectInfoManager) {
        JSHelper.combotreeProject('ProjectId');
    }
}
function openPhase(row) {
    //var row = JSHelper.isDatagridSelected($("#Grid"));
    if (row == null) return;
    if (!self.parent.projectInfoManager) {
        self.parent.addTab("项目回款收入", "Project/ProjectPhaseInfo.htm", "icon-edit");
        self.parent.public_ids.options["ProjectProgressId"] = row.Id;
    } else {
        self.parent.projectInfoManager.addTab("项目回款收入", "ProjectPhaseInfo.htm", "icon-edit");
        self.parent.parent.public_ids.options["ProjectProgressId"] = row.Id;
    }
}

function Initlist(size) {
    if (self.parent.projectInfoManager) {
        JSUtility.param.Options["ProjectId"] = self.parent.parent.project_id;
        JSUtility.replenish = function() {
            $("#ProjectId").val(self.parent.parent.project_id);
        };
        $("#ProjectId").attr("readonly", "readonly");
    }
    JSUtility.param.Method = "Search";
    JSUtility.grid = $('#Grid').datagrid({
        tilte: '添加项目执行信息',
        iconCls: 'icon-save',
        width: size.width,
        height: size.height,
        pageSize: Math.round(size.height / 25),
        pageList: [Math.round(size.height / 25)],
        nowrap: true,
        striped: true,
        url: JSUtility.url,
        queryParams: { "json": $.toJSON(JSUtility.param) },
        sortName: 'Id',
        sortOrder: 'desc',
        idField: 'Id',
        frozenColumns: [[
            { title: '编号', field: 'Id', width: 50, sortable: true }
            ]],
        columns: [[

                    { title: '项目编号', field: 'ProjectId', width: 80 },
                    { title: '项目名称', field: 'ProjectName', width: 100 },
                    { title: '前季度工作量(季度)', field: 'TotalWorkPreviousQuarter', width: 100 },
                    { title: '前季度工作量(%)', field: 'TotalWorkPrecentPreviousQuarter', width: 100 },
                    { title: '上季度工作量(季度)', field: 'WorkPlanLastQuarter', width: 100 },
                    { title: '上季度工作量(%)', field: 'WorkPlanPrecentLastQuarter', width: 100 },
                    { title: '上季度工作量落实累计(季度)', field: 'TotalWorkLastQuarter', width: 100 },
                    { title: '上季度工作量落实累计(%)', field: 'TotalWorkPrecentLastQuarter', width: 100 },
                    { title: '本季度工作量计划(季度)', field: 'WorkPlanThisQuarter', width: 100 },
                    { title: '本季度工作量计划(%)', field: 'WorkPlanPrecentThisQuarter', width: 100 },
                    { title: '计划累计(%)', field: 'PlanTotal', width: 100 }

                  ]],
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        toolbar: [
                    {
                        text: '添加',
                        iconCls: 'icon-add',
                        handler: JSUtility.add
                    }, '-',
                    {
                        text: '修改',
                        iconCls: 'icon-edit',
                        handler: function() {
                            JSUtility.update();
                            JSHelper.conbotreeUpdateProject("ProjectId");
                        }
                    }, '-',
                    {
                        text: '删除',
                        iconCls: 'icon-remove',
                        handler: JSUtility.del
                    }, '-',
                    {
                        text: '查询',
                        iconCls: 'icon-search',
                        handler: JSUtility.search
                    }
                   , '-',
                   {
                       text: '所属阶段',
                       iconCls: 'icon-edit',
                       handler: function() {
                           var row = JSHelper.isDatagridSelected($("#Grid"));
                           if (row == null) return;
                           if (!self.parent.projectInfoManager) {
                               self.parent.addTab("项目设计所属阶段", "Project/ProjectPhaseInfo.htm", "icon-edit");
                               self.parent.public_ids.options["ProjectProgressId"] = row.Id;
                               self.parent.public_ids.options["ProjectId"] = row.ProjectId;
                           } else {
                               self.parent.projectInfoManager.addTab("项目设计所属阶段", "ProjectPhaseInfo.htm", "icon-edit");
                               self.parent.parent.public_ids.options["ProjectProgressId"] = row.Id;
                               self.parent.parent.public_ids.options["ProjectId"] = row.ProjectId;
                           }
                       }
                   }
                 ]
    });
}